package com.pro01.backend.mapper;

import org.apache.ibatis.annotations.*;

@Mapper
public interface Forum2CommentLikeMapper {

    @Insert("""
        INSERT INTO forum2_comment_likes (user_id, comment_id)
        VALUES (#{userId}, #{commentId})
    """)
    int insertLike(@Param("userId") Long userId, @Param("commentId") Long commentId);

    @Delete("""
        DELETE FROM forum2_comment_likes
        WHERE user_id = #{userId} AND comment_id = #{commentId}
    """)
    int deleteLike(@Param("userId") Long userId, @Param("commentId") Long commentId);

    @Select("""
        SELECT COUNT(*) FROM forum2_comment_likes
        WHERE user_id = #{userId} AND comment_id = #{commentId}
    """)
    boolean hasLiked(@Param("userId") Long userId, @Param("commentId") Long commentId);

    @Update("""
        UPDATE forum2_comments
        SET like_count = like_count + 1
        WHERE id = #{commentId}
    """)
    int incrementLikeCount(@Param("commentId") Long commentId);

    @Update("""
        UPDATE forum2_comments
        SET like_count = GREATEST(like_count - 1, 0)
        WHERE id = #{commentId}
    """)
    int decrementLikeCount(@Param("commentId") Long commentId);
}

